package Offer;

public class Test49 
{

	public static void main(String[] args) 
	{
         String str="-1";
         System.out.println(strToInt(str));

	}
	public static int strToInt(String str)
	{
		boolean InvalidInput=false;
		if(str==null||str.length()==0||str=="")
		{
			InvalidInput=true;
			return 0;
		}
		char[] ch=str.toCharArray();
		boolean minus = false;
		int i=0;
		int num = 0;
		if(ch[0]=='+')
		{
			i=1;
		}
		if(ch[0]=='-')
		{
			minus = true;
			i=1;
		}
		while(i<ch.length)
		{
			if(ch[i]>='0'&&ch[i]<='9')
				num += (int)(ch[i]-'0')*Math.pow(10.0, ch.length-1-i);
			else
		    {
				InvalidInput=true;
				return 0;
		    }
			++i;
		}
		if(minus)
		{
			num=0-num;
		}
		return num;	
			
			
	}

}
